<template>
 <div  class="components-container">
        <sweet-modal ref="dialog" class="dialog">
            <h3>{{ title }}</h3>
             <div style=" height:200px; margin:30px 50px">
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">问题</label>
                  <div class="layui-input-inline">
                   <el-input type="textarea" placeholder="请输入问题" style="width: 495px;"  v-model="problem.question"></el-input> 
                  </div>

                </div>
              </div>
                 <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">回答</label>
                  <div class="layui-input-inline">
                   <el-input type="textarea" placeholder="请输入回答" style="width: 495px;"   v-model="problem.answer"></el-input> 
                  </div>
                </div>
              </div>
                 
               <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否显示</label>
                    <el-radio-group  class="layui-input-inline" v-model="problem.radio" >
                         <el-radio  label="B">是</el-radio>
                         <el-radio  label="A">否</el-radio>
                    </el-radio-group>
                </div>
               <div class="layui-inline">
                <label class="layui-form-label">序号</label>
                <div class="layui-input-inline">
                   <el-input type="text"   v-model="problem.JPTNUM"  placeholder="请输入序号" oninput ="value=value.replace(/[^\d]/g,'')"></el-input>
                </div>
                </div>
            </div>
             </div>

            <div class="layui-form-item btnCenter">
              <el-button @click="closeDialog">取消</el-button>
              <el-button type="primary" @click="submit" :loading="loading">确定</el-button>
            </div>
        </sweet-modal>
<!-- 详情 -->
         <sweet-modal ref="dialogInfo" class="dialog">
              <h3>{{ title }}</h3>
               <div style=" height:200px; margin:30px 50px">

             <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">问题</label>
                  <div class="layui-input-inline">
                   <el-input type="textarea" placeholder="请输入问题" style="width: 495px;"  v-model="problem.JPPPROBLEM" readonly></el-input> 
                  </div>

                </div>
              </div>
               <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">回答</label>
                  <div class="layui-input-inline">
                   <el-input type="textarea" placeholder="请输入回答" style="width: 495px;"   v-model="problem.JPPANSWER" readonly ></el-input> 
                  </div>
                </div>
              </div>
             
               <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否显示</label>
                    <el-radio-group  class="layui-input-inline" v-model="problem.JPPISLOGO" disabled >
                         <el-radio  readonly label="B">是</el-radio>
                         <el-radio  readonly label="A">否</el-radio>
                    </el-radio-group>
                </div>
               <div class="layui-inline">
                <label class="layui-form-label">日期时间</label>
                <div class="layui-input-inline">
                    <el-date-picker type="datetime" v-model="regDateTimeInfo" format="yyyy-MM-dd HH:mm" readonly></el-date-picker>
                </div>
            </div>
               </div>
               </div>
         </sweet-modal>
 </div>
 
</template>
<style  rel="stylesheet/scss" lang="scss" scoped>
.el-radio {
  margin: 10px 25px;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import apiBase from "@/api/apiBase.js";
import {
  formatDate,
  timeStringToDate,
  dateStringToDate
} from "@/utils/date.js";
const ADD = "新增";
const INFO = "详情";
export default {
  name: "DepartmentMatter",
  data() {
    return {
      regDateTimeInfo: null,
      isDetail: true,
      departData: [],
      sthtype: [],
      title: null,
      loading: false,
      problem: {
        question: "",
        answer: "",
        radio: true
      }
    };
  },
  methods: {
    //功能操作
    open(order, id) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "新增";
          this.initSelectData();
          this.$refs.dialog.open();
          break;

        case INFO:
          this.title = "详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;

        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },

    //数据重置
    dataRepeat() {
      this.problem = {};
    },

    //获取部门下拉
    getdepartDatas() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().JointRegConclude.DetailAllJointDept,
        res => {
          this.departData = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    // 获取联办办事事项类型
    getsthtype() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Sendcar.GetJptType,
        res => {
          this.sthtype = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //初始化下拉框数据
    initSelectData() {
      this.getdepartDatas();
      this.getsthtype();
    },
    //新增提交
    dataAdd() {
      this.loading = true;

      let Data = {
        JPPPROBLEM: this.problem.question,
        JPPANSWER: this.problem.answer,
        JPPISLOGO: this.problem.radio,
        JPTNUM: this.problem.JPTNUM
      };
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().JointRegConclude.CreateJointCommonProblem,
        res => {
          this.loading = false;
          this.$refs.dialog.close();

          this.$message({
            type: "success",
            message: "新增成功!"
          });
          this.refreshData();
        },
        res => {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
      );
    },

    //详情
    dataInfo(id) {
      let data = {
        JPPID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().JointRegConclude.DetailJointCommonProblem,
        res => {
          this.problem = res.data.content;
          this.regDateTimeInfo = timeStringToDate(
            //详情中的到馆时间
            res.data.content.JPPINPUTTIME,
            res.data.content.JPPINPUTDATE,
        
          );
        }
      );
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    },

    refreshData() {
      this.$emit("refreshData");
    }
  },
  components: {
    formatDate,
    sweetModal
  }
};
</script>


